//
//  LY_Item_View.m
//  iSee
//
//  Created by dllo on 16/8/6.
//  Copyright © 2016年 LY. All rights reserved.
//

#import "SE_Item_View.h"
#import "SE_Cover_TableViewCell.h"
#import "SE_Desc_TableViewCell.h"
#import "SE_Item_Model.h"

#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height

@interface SE_Item_View()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@end

@implementation SE_Item_View

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createTableView];
    }
    return self;
}

-(void)createTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    [self addSubview:self.tableView];
    self.tableView.bounces = NO;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[SE_Cover_TableViewCell class] forCellReuseIdentifier:@"coverCell"];
    [self.tableView registerClass:[SE_Desc_TableViewCell class] forCellReuseIdentifier:@"descCell"];
}

-(NSInteger)tableView:(UITableView *)tSEableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
       SE_Cover_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"coverCell"];
        cell.itemModel = self.itemModel;
        return cell;
    } else {
        SE_Desc_TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"descCell"];
        cell.itemModel = self.itemModel;
        cell.backgroundColor = [UIColor colorWithRed:0.41 green:0.42 blue:0.39 alpha:1.0];
        return cell;
    }
}

-(void)setItemModel:(SE_Item_Model *)itemModel
{
    _itemModel = itemModel;
    [self.tableView reloadData];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return self.bounds.size.height * 0.45;
    } else {
        return self.bounds.size.height * 0.55;
    }
}

@end



















